﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using Microsoft.ApplicationBlocks.Data;
namespace FrameWork.web.Code
{
    public class AllSeach
    {
        public AllSeach()
        {
            Microsoft.ApplicationBlocks.Data.SqlHelper.connectionString = ConfigurationManager.AppSettings["MsSql"].ToString();
        }
        /// <summary>
        /// 通用分布查询
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <param name="ReturnFields">需要返回的列</param>
        /// <param name="PageSize">每页记录数</param>
        /// <param name="PageIndex">当前页码</param>
        /// <param name="Where">查询条件</param>
        /// <param name="Orderfld">排序字段名 最好为唯一主键</param>
        /// <param name="OrderType">排序类型 1:降序 其它为升序</param>
        /// <returns></returns>
        public DataSet SupesoftPage(string TableName, string ReturnFields, int PageSize, int PageIndex, string Where, string Orderfld, string OrderType)
        {
            SqlParameter[] sp = new SqlParameter[7]{
				new SqlParameter("@TableName",SqlDbType.NVarChar,50),
				new SqlParameter("@ReturnFields",SqlDbType.NVarChar,2000),
				new SqlParameter("@PageSize",SqlDbType.Int),
				new SqlParameter("@PageIndex",SqlDbType.Int),
				new SqlParameter("@Where",SqlDbType.NVarChar,2000),
				new SqlParameter("@Orderfld",SqlDbType.NVarChar,2000),
				new SqlParameter("@OrderType",SqlDbType.Int),
			
			};
            //

            sp[0].Value = TableName;
            sp[0].Direction = ParameterDirection.Input;


            //

            sp[1].Value = ReturnFields;
            sp[1].Direction = ParameterDirection.Input;


            //

            sp[2].Value = PageSize;
            sp[2].Direction = ParameterDirection.Input;


            //

            sp[3].Value = PageIndex;
            sp[3].Direction = ParameterDirection.Input;


            //

            sp[4].Value = Where;
            sp[4].Direction = ParameterDirection.Input;


            //

            sp[5].Value = Orderfld;
            sp[5].Direction = ParameterDirection.Input;


            //

            sp[6].Value = OrderType;
            sp[6].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.SupesoftPage", sp);
           
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
